import presetWeapp from 'unocss-preset-weapp'
import { defineConfig } from 'unocss'
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer'
const { transformerAttributify, presetWeappAttributify } = extractorAttributify()
export default defineConfig({
  presets: [
    // https://github.com/MellowCo/unocss-preset-weapp
    presetWeapp({
      // h5兼容
      // 只开发小程序可删除
      platform: 'uniapp',
      isH5: process.env.UNI_PLATFORM === 'h5',
    }),

    // attributify autocomplete
    presetWeappAttributify(),
  ],
/*  rules: [
    // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/rules
    ...presetWeapp.rules,
      // 高度
      [/^h-(\d+)$/, ([, d]) => ({ height: `${d}rpx` })],
      // 宽度
      [/^w-(\d+)$/, ([, d]) => ({ width: `${d}rpx` })],
    // ========== Margin 边距 ==========
    [/^m-(\d+)$/, ([, d]) => ({ margin: `${d}rpx` })],
    [/^mt-(\d+)$/, ([, d]) => ({ 'margin-top': `${d}rpx` })],
    [/^mb-(\d+)$/, ([, d]) => ({ 'margin-bottom': `${d}rpx` })],
    [/^ml-(\d+)$/, ([, d]) => ({ 'margin-left': `${d}rpx` })],
    [/^mr-(\d+)$/, ([, d]) => ({ 'margin-right': `${d}rpx` })],
    [/^mx-(\d+)$/, ([, d]) => ({ 'margin-left': `${d}rpx`, 'margin-right': `${d}rpx` })],
    [/^my-(\d+)$/, ([, d]) => ({ 'margin-top': `${d}rpx`, 'margin-bottom': `${d}rpx` })],

    // ========== Padding 内边距 ==========
    [/^p-(\d+)$/, ([, d]) => ({ padding: `${d}rpx` })],
    [/^pt-(\d+)$/, ([, d]) => ({ 'padding-top': `${d}rpx` })],
    [/^pb-(\d+)$/, ([, d]) => ({ 'padding-bottom': `${d}rpx` })],
    [/^pl-(\d+)$/, ([, d]) => ({ 'padding-left': `${d}rpx` })],
    [/^pr-(\d+)$/, ([, d]) => ({ 'padding-right': `${d}rpx` })],
    [/^px-(\d+)$/, ([, d]) => ({ 'padding-left': `${d}rpx`, 'padding-right': `${d}rpx` })],
    [/^py-(\d+)$/, ([, d]) => ({ 'padding-top': `${d}rpx`, 'padding-bottom': `${d}rpx` })],

    // ========== Width/Height 宽高 ==========
    [/^w-(\d+)$/, ([, d]) => ({ width: `${d}rpx` })],
    [/^h-(\d+)$/, ([, d]) => ({ height: `${d}rpx` })],
    [/^min-w-(\d+)$/, ([, d]) => ({ 'min-width': `${d}rpx` })],
    [/^min-h-(\d+)$/, ([, d]) => ({ 'min-height': `${d}rpx` })],
    [/^max-w-(\d+)$/, ([, d]) => ({ 'max-width': `${d}rpx` })],
    [/^max-h-(\d+)$/, ([, d]) => ({ 'max-height': `${d}rpx` })],
    [/^w-full$/, () => ({ width: '100%' })],
    [/^h-full$/, () => ({ height: '100%' })],

    // ========== Position 定位 ==========
    [/^top-(\d+)$/, ([, d]) => ({ top: `${d}rpx` })],
    [/^right-(\d+)$/, ([, d]) => ({ right: `${d}rpx` })],
    [/^bottom-(\d+)$/, ([, d]) => ({ bottom: `${d}rpx` })],
    [/^left-(\d+)$/, ([, d]) => ({ left: `${d}rpx` })],
    [/^inset-(\d+)$/, ([, d]) => ({ top: `${d}rpx`, right: `${d}rpx`, bottom: `${d}rpx`, left: `${d}rpx` })],

    // ========== Text 文本 ==========
    [/^text-(\d+)$/, ([, d]) => ({ 'font-size': `${d}rpx` })],
    [/^leading-(\d+)$/, ([, d]) => ({ 'line-height': `${d}rpx` })],
    [/^tracking-(\d+)$/, ([, d]) => ({ 'letter-spacing': `${d}rpx` })],

    // ========== Border 边框 ==========
    [/^rounded-(\d+)$/, ([, d]) => ({ 'border-radius': `${d}rpx` })],
    [/^border-(\d+)$/, ([, d]) => ({ 'border-width': `${d}rpx` })],
    [/^border-t-(\d+)$/, ([, d]) => ({ 'border-top-width': `${d}rpx` })],
    [/^border-b-(\d+)$/, ([, d]) => ({ 'border-bottom-width': `${d}rpx` })],
    [/^border-l-(\d+)$/, ([, d]) => ({ 'border-left-width': `${d}rpx` })],
    [/^border-r-(\d+)$/, ([, d]) => ({ 'border-right-width': `${d}rpx` })],

    // ========== Gap 间距 ==========
    [/^gap-(\d+)$/, ([, d]) => ({ gap: `${d}rpx` })],
    [/^gap-x-(\d+)$/, ([, d]) => ({ 'column-gap': `${d}rpx` })],
    [/^gap-y-(\d+)$/, ([, d]) => ({ 'row-gap': `${d}rpx` })],

    ['bg-white', { 'background-color': '#ffffff' }],
    ['bg-black', { 'background-color': '#000000' }],
    ['text-gray', { color: '#8E949F' }],
    ['text-white', { color: '#ffffff' }],
    ['text-black', { color: '#000000' }],
    ['bg-lgColor', { background: 'linear-gradient(90deg,rgb(176, 36, 240) 0%,rgb(55, 114, 239) 100%)' }],
  ],*/
  transformers: [
    // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify
    transformerAttributify(),
    // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass
    transformerClass(),
  ],
})
